#!/usr/bin/env python3
import os
import logging


def password_check(func):
    def wrapper(*args, **kwargs):
        name = args[0]
        password = args[1]
        logging.debug(name, password)

        lower = False
        upper = False
        number = False
        special = False

        for i in password:
            if i.isdigit():
                number = True
            elif i.islower():
                lower = True
            elif i.isupper():
                upper = True
            else:
                special = True

        if number is False:
            print('没有数字')
        elif lower is False:
            print('没有小写字母')
        elif upper is False:
            print('没有大写字母')
        elif special is False:
            print('没有特殊字母')
        else:
            return func(*args, **kwargs)

    return wrapper


@password_check
def set_user_password(user, password):
    os.system(
        'echo {0} | passwd {1} --stdin >/dev/null && echo set password ok'.
        format(password, user))


@password_check
def set_mysql_password(user, password):
    pass


def main():
    name = input('please input user name:')
    password = input('please input password:')
    set_user_password(name, password)


main()
